home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj0587.arc / COMLIN.ASM next >
Assembly Source File  |  1987-03-19  |  2KB  |  76 lines

  1. ; Microsoft Fortran-callable function to retrieve command line data
  2. ; Copyright (C)  John W. Ross  1986
  3.  
  4. ; Calling format:
  5.  
  6. ;   N = COMLIN (COMARG)
  7. ;
  8. ;    COMLIN    must be declared to return an integer (short or long)
  9. ;
  10. ;    N    a short or long integer--the number of characters on
  11. ;        the command line following the program name
  12. ;
  13. ;    COMARG    a CHARACTER*127 variable--the portion of the command
  14. ;        line which follows the program name
  15.  
  16. ; equates 
  17. psp_seg    equ    4fh    ; program segment prefix segment
  18. psp_off    equ    2    ; program segment prefix offset
  19. max_len    equ    127    ; length of command line data
  20. len_off    equ    80h    ; offset of command line length
  21. blank    equ    20h    ; blank character
  22.  
  23. cseg    segment 'code'        ; define the code segment
  24.     assume  cs:cseg
  25.  
  26. public    comlin            ; make it known outside 
  27. comlin    proc    far
  28.  
  29.     push    bp        ; save Fortran's registers
  30.     mov    bp,sp
  31.     push    ds
  32.  
  33.     push    ds        ; point the extra segment at ds
  34.     pop    es
  35.  
  36. ; retrieve the number of characters on the command line
  37.     mov    dx,psp_seg    ; load the location of the psp
  38.     mov    ds,dx        ; into bx
  39.     mov    bx,psp_off
  40.     mov    dx,[bx]
  41.     mov    ds,dx        ; the psp is now the data segment
  42.     mov    bx,len_off    ; offset for the command line length
  43.     mov    ah,0
  44.     mov    al,[bx]        ; command line length now in al
  45.     cmp    ax,0        ; if its zero, return
  46.     je    exit
  47.  
  48. ; first, blank out COMARG
  49.     les    bx,dword ptr[bp+6]    ; the address of COMARG
  50.     xor    cx,cx        ; zero cx
  51.     mov    cl,max_len    ; set up for looping
  52. clr:    mov    es:[bx],byte ptr blank
  53.     inc    bx
  54.     loop    clr
  55.  
  56. ; now, put the actual command line data into COMARAG
  57.     les    bx,dword ptr[bp+6]    ; the address of COMARG
  58.     mov    cx,ax        ; # of characters on command line
  59.     mov    si,len_off+1    ; where the command line data starts
  60. load:    mov    dl,[si]        ; get a character 
  61.     mov    es:[bx],dl    ; move it to COMARG
  62.     inc    bx
  63.     inc    si
  64.     loop    load
  65.  
  66. exit:    mov    dx,0        ; so we can return a long integer
  67.         pop     ds        ; restore Fortran's registers
  68.         mov     sp,bp
  69.         pop     bp
  70.         ret     4
  71.  
  72. comlin    endp
  73. cseg    ends
  74.  
  75.     end
  76.